package com.dw.etl.core.controller;

import com.dw.etl.common.base.BaseException;
import com.dw.etl.common.base.BaseResult;
import com.dw.etl.common.constant.CommonResultConstant;
import com.dw.etl.common.vo.FieldAttrVO;
import com.dw.etl.common.vo.PaginationVO;
import com.dw.etl.core.api.BaseDbInfoService;
import com.dw.etl.core.api.BaseDbService;
import com.dw.etl.core.bean.model.BaseDb;
import com.dw.etl.core.bean.vo.LayMsg;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * baseDb控制器
 * Created by hozeData on 2021/05/21.
 */
@RestController
@RequestMapping("/etl/baseDbInfo/")
@Api(tags = "数据源")
@CrossOrigin(origins = "*", maxAge = 3600)
public class BaseDbInfoController {

    @Autowired
    BaseDbInfoService baseDbInfoService;

    @ApiOperation(value = "获取数据库表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "idDb", value = "主键", paramType = "query", required = true, dataType = "Long"),
            @ApiImplicitParam(name = "tableName", value = "表名称", paramType = "query", required = true, dataType = "Long")
    })

    @RequestMapping(value = "getTables", method = RequestMethod.GET)
    public BaseResult getTables(Long idDb, String tableName,HttpServletRequest request) throws BaseException {
        List<FieldAttrVO> list = baseDbInfoService.getTables(idDb,tableName);

        return new BaseResult(CommonResultConstant.SUCCESS, list);
    }

    @ApiOperation(value = "获取数据量表信息")
    @ApiImplicitParam(name = "getTableInfo", value = "主键", paramType = "query", required = true, dataType = "Long")
    @RequestMapping(value = "getTableInfo", method = RequestMethod.GET)
    public BaseResult getTableInfo(Long idDb, String tables, HttpServletRequest request) throws BaseException {
        List<FieldAttrVO> list = baseDbInfoService.getTableInfo(idDb,tables);

        return new BaseResult(CommonResultConstant.SUCCESS, list);
    }

}
